package com.lanou.test.controller;


import com.lanou.test.bean.ResultObject;
import com.lanou.test.bean.User;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")
public class UserController {

    @RequestMapping("/login")
    public ResultObject login(User user){
        ResultObject object = new ResultObject();
        try {
            Subject subject = SecurityUtils.getSubject();
            AuthenticationToken token = new UsernamePasswordToken(user.getUsername(), user.getPwd());
            subject.login(token);

            //subject.isAuthenticated()
            //subject.getPrincipals()获得特征
            object.setStatus(1);
            object.setInfo("登陆成功");
        }catch (Exception e){
            object.setStatus(0);
            object.setInfo("登陆失败");

        }
        return object;
    }
}
